package com.boxuegu.guanweihua25.databinding.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableField;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.boxuegu.guanweihua25.databinding.Apis;
import com.boxuegu.guanweihua25.databinding.BR;
import com.boxuegu.guanweihua25.databinding.R;

import com.boxuegu.guanweihua25.databinding.databinding.ActivityRetrofitLoginBinding;
import com.boxuegu.guanweihua25.databinding.model.RetrofitLoginModel;
import com.boxuegu.guanweihua25.databinding.utils.RetrofitUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RetrofitLoginActivity extends AppCompatActivity {
    ObservableField<String>username=new ObservableField<>();
    ObservableField<String>password=new ObservableField<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityRetrofitLoginBinding binding=
        DataBindingUtil.setContentView(this,
                R.layout.activity_retrofit_login);

        binding.setUsername(username);
        binding.setPassword(password);
binding.recycleview.setAdapter(new MyAdapter());
        binding.setVariable(BR.myclick,new MyClick());
        binding.recycleview.setLayoutManager(new LinearLayoutManager(this));


//        setContentView(R.layout.activity_retrofit_login);

    }
    public  class MyClick{
        public void onClick(View view){

            Call<RetrofitLoginModel> bannerModelCall= RetrofitUtils.getRetrofit().create(Apis.class)
                    .getLogin(username.get(),password.get());
            bannerModelCall.enqueue(new Callback<RetrofitLoginModel>() {
                @Override
                public void onResponse(Call<RetrofitLoginModel> call, Response<RetrofitLoginModel>
                        response) {
                    RetrofitLoginModel loginModel=response.body();
                    if(response.body().code ==0){
                        //跳主页面

                    }else{
//弹出toast提示
                    }

                }


                @Override
                public void onFailure(Call<RetrofitLoginModel> call, Throwable t) {

                }
            });
        }
    }
    public class  MyAdapter extends RecyclerView.Adapter<MyViewHolder>{

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            return null;
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {

        }

        @Override
        public int getItemCount() {
            return 0;
        }
    }
    public class MyViewHolder extends RecyclerView.ViewHolder{

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
